package com.ssoclient.services;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.ssoclient.entity.User;
import com.ssoclient.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 11900
 * @version V1.0
 * @Title: ${FILE_NAME}
 * @Package com.ssoclient.services
 * @Description: TODO
 * @date 2020/4/29 11:37
 */
@Service
public class IUserServiceImpl implements IUserService {
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public User getUserByToken(String token) {
        if (StrUtil.isEmpty(token)) {
            return null;
        }
        if (redisUtil.hasKey(token)){
            //由于USER没有在同一个包下，所以fastjson反序列化失败
            User user =  JSONUtil.toBean(JSONUtil.toJsonStr(redisUtil.get(token)), User.class);
            return user;
        }
        return null;
    }
}
